﻿@model MvcAtletIS.Models.Statistics

@{
    ViewBag.Title = "Pridať záznam";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<h2>Pridať záznam</h2>


@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Detaily</legend>

        <div class="editor-label">
            Klub
        </div>
        <div class="editor-field">
            @Html.DropDownList("ClubId", "Vyberte klub")
        </div>
                
        <div class="editor-label">
            @Html.LabelFor(model => model.CompetitorId)
        </div>
        <div class="editor-field">
            @Html.DropDownList("CompetitorId", "Vyberte pretekára")
            @Html.ValidationMessageFor(model => model.CompetitorId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DisciplineId)
        </div>
        <div class="editor-field">
            @Html.DropDownList("DisciplineId", "Vyberte disciplínu")
            @Html.ValidationMessageFor(model => model.DisciplineId)
        </div>
        
        <div class="editor-label">
            @Html.LabelFor(model => model.Year)
        </div>
        <div class="editor-field">
            @Html.DropDownList("Year", "Vyberte rok")
        </div>
                
        <div class="editor-label">
            @Html.LabelFor(model => model.CompetitionId)
        </div>
        <div class="editor-field">
            @Html.DropDownList("CompetitionId", "Vyberte preteky")
            @Html.ValidationMessageFor(model => model.CompetitionId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Result)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Result)
            @Html.ValidationMessageFor(model => model.Result)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.sResult)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.sResult)
            @Html.ValidationMessageFor(model => model.sResult)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Rank)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Rank)
            @Html.ValidationMessageFor(model => model.Rank)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Indoor)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Indoor)
            @Html.ValidationMessageFor(model => model.Indoor)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Electronic)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Electronic)
            @Html.ValidationMessageFor(model => model.Electronic)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Note)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Note)
            @Html.ValidationMessageFor(model => model.Note)
        </div>

        <p>
            <input type="submit" value="Pridať" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Naspäť na editor štatistiky", "Index", new { Year = @ViewBag.Year.SelectedValue, ClubId = @ViewBag.ClubId.SelectedValue, CompetitorId = @ViewBag.CompetitorId.SelectedValue })
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $("#Year").change(function () {
            var idModel = $(this).val();
            $.getJSON("/Admin/Statistics/LoadStatCompForYear", { id: idModel }, function (comboData) {
                var select = $("#CompetitionId");
                select.empty();
                select.append($('<option/>',
                {
                    value: null,
                    text: "Vyberte preteky"
                }));
                $.each(comboData, function (index, itemData) {
                    select.append($('<option/>',
                    {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });
    });
</script>


<script type="text/javascript">
    $(document).ready(function () {
        $("#ClubId").change(function () {
            var idModel = $(this).val();
            $.getJSON("/Admin/Statistics/LoadCompetitorsForClub", { id: idModel }, function (comboData) {
                
                var select = $("#CompetitorId");
                select.empty();
                select.append($('<option/>',
                {
                    value: null,
                    text: "Vyberte pretekára"
                }));
                $.each(comboData, function (index, itemData) {
                    select.append($('<option/>',
                    {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });
    });
</script>


